package com.xinyan.config;

import com.alibaba.fastjson.JSON;
import com.github.xingshuangs.iot.protocol.s7.enums.EPlcType;
import com.github.xingshuangs.iot.protocol.s7.service.S7PLC;
import com.xinyan.dto.SprayHostDTO;
import com.xinyan.mapper.SprayHostMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Configuration
@Slf4j
public class SmartConfig {


    @Autowired
    private SprayHostMapper sprayHostMapper;

    @Bean
    public Map<Integer, S7PLC> s7PLCMap(){
        Map<Integer, S7PLC> map = new HashMap<>();
        List<SprayHostDTO> sprayHostDTOS = sprayHostMapper.selectSprayHostList();
        sprayHostDTOS.forEach(e -> map.put(e.getId(),new S7PLC(EPlcType.S200_SMART, e.getIp())));
        System.out.println(JSON.toJSONString(map));
        log.info("========成功注册主机：{}========", JSON.toJSONString(map,true));
        return map;
    }

    @Bean
    public List<Integer> testIdList(){
        List<Integer> list = new ArrayList<>();
        list.add(1);
        return list;
    }

}
